$(document).ready(function () {
  $("#caledar_from").datepicker({
    changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy", yearRange: "1930:2050"
  });
  $("#caledar_to").datepicker({
    changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy", yearRange: "1930:2050"
  });
  $(".datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: 'yy-mm-dd',
    yearRange: '2013:2050'
  });
  $(".custom_chk").jqTransCheckBox();
  $(".custom_rd").jqTransRadio();
  $(".custom_select").jqTransSelect();
  //$(".fancyboxClick").fancybox();
  $("#saveContent").click(function () {
    $("#loader").fadeIn()
  });
  $(".gr_perm_error").width($(".right_content").width() - 2);
  $(".gr_perm_success").width($(".right_content").width() - 2);
  $("#frmManagement input").keypress(function (b) {
      if (b.which == 13) {
        save();
        return false
      }
    }
  );
  var a = $.url(document.location.href);
  if (a.segment(-1) != "update" && a.segment(-2) != "update") {
    if (a.fsegment(1) == "back" || a.fsegment(1) == "save") {
      if (a.fsegment(1) == "save") {
        show_perm_success()
      }
      if (a.segment(-1) != "update_profile" && a.segment(-1) != "setting") {
        if ($("#start").val() == "") {
          $("#start").val(0)
        }
        searchContent($("#start").val(), 10)
      }
    } else {
      console.log(a.segment(-1), a.segment(-2),module);
      if (a.segment(-1) != "update_profile" && a.segment(-1) != "setting" && a.segment(-1) != "views") {
        if (module != "dashboard") {
          searchContent(0, 10)
        }
      }
    }
  }
});
function enterSearch(a) {
  if (a.keyCode == 13) {
    searchContent(0)
  }
}
function searchContent(d, b) {
  if (b == undefined) {
    if ($("#per_page").val()) {
      b = $("#per_page").val()
    } else {
      b = 10
    }
  }
  var a = $("#func_sort").val();
  var c = $("#type_sort").val();
  $("#start").val(d);
  $.post(
    root + "/" + module + "/ajaxLoadContent", {
      func_order_by: a,
      order_by: c,
      start: d,
      per_page: b,
      dateFrom: $("#caledar_from").val(),
      dateTo: $("#caledar_to").val(),
      content: $("#search_content").val()
    }, function (e) {
      $("#ajax_loadContent").html(e);
      $(".custom_chk").jqTransCheckBox();
      //$(".fancyboxClick").fancybox();
      $(".sort").removeClass("icon_sort_desc");
      $(".sort").removeClass("icon_sort_asc");
      $(".sort").addClass("icon_no_sort");
      if (c == "DESC") {
        $("#" + a).addClass("icon_sort_desc")
      } else {
        $("#" + a).addClass("icon_sort_asc")
      }
    })
}
function selectAllItems(a) {
  if (document.getElementById("selectAllItems").checked == true) {
    $(".jqTransformCheckboxWrapper a").addClass("jqTransformChecked");
    for (var b = 0; b < a; b++) {
      if (document.getElementById("item" + b) != null) {
        $(".item_row" + b).addClass("row_active");
        itemCheck = document.getElementById("item" + b);
        itemCheck.checked = true
      }
    }
  } else {
    $(".jqTransformCheckboxWrapper a").removeClass("jqTransformChecked");
    for (var b = 0; b < a; b++) {
      if (document.getElementById("item" + b) != null) {
        $(".item_row" + b).removeClass("row_active");
        itemCheck = document.getElementById("item" + b);
        itemCheck.checked = false
      }
    }
  }
}
function selectItem(b) {
  var a = document.getElementById("item" + b);
  if (a.checked == false) {
    $(".item_row" + b).addClass("row_active")
  } else {
    $(".item_row" + b).removeClass("row_active")
  }
}